var express = require('express');
var router = express.Router();
// var process = require('process');
var path = require('path');
var fs = require('fs');

router.get('/', function (req, res, next) {
  fs.readdir(path.join(__dirname, '../download/'), function (err, files) {
    res.header('Access-Control-Allow-Origin', '*');
    res.send(files);
    console.log('sent' + files);
  });

});

/* GET file. */
router.get('/:file', function(req, res, next) {
  var filename = req.params.file;
  var filepath = path.join(__dirname, '../download/', filename);
  res.header('Access-Control-Allow-Origin', '*');
  res.download(filepath);
  // res.send('respond with a resource');
});

module.exports = router;
